package zhengqc.common;

import java.util.Objects;

public class Tuple<A extends Comparable<A>, B extends Comparable<B>> implements Comparable<Tuple<A, B>> {
    public A first;
    public B second;

    public Tuple(A first, B second) {
        this.first = first;
        this.second = second;
    }

    @Override
    public String toString() {
        return String.format("(%d, %d)", this.first, this.second);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Tuple<?, ?> tuple = (Tuple<?, ?>) o;
        return Objects.equals(first, tuple.first) &&
                Objects.equals(second, tuple.second);
    }

    @Override
    public int hashCode() {
        return Objects.hash(first, second);
    }

    @Override
    public int compareTo(Tuple<A, B> op) {
        if ( this.first.compareTo(op.first) == 0 ) {
            if ( this.second.compareTo(op.second) == 0 ) {
                return 0;
            }
            return this.second.compareTo(op.second);
        }
        return this.first.compareTo(op.first);
    }
}
